package com.sumbo.streams;

import com.alibaba.fastjson.JSON;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

/**
 * \* User: MeiZhongHao
 * \* Date: 2019-05-30
 * \* Time: 15:56
 * \* Description:
 * \
 */
public class KafkaStreamProducer {


    public static void main(String[] args) throws InterruptedException {
        Properties props = new Properties();
        props.put("bootstrap.servers", "localhost:9092");
        props.put("acks", "all");
        props.put("retries", 1);
        props.put("batch.size", 16384);
        props.put("linger.ms", 1);
        props.put("buffer.memory", 33554432);
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

        Producer<String, String> producer = new KafkaProducer<>(props);
        for (int i = 0; i < 1; i++) {
            String message = "all name sql my";
            producer.send(new ProducerRecord<String, String>("word", Integer.toString(i), message));
            System.out.println("测试发送消息:" + JSON.toJSONString(message));
            Thread.sleep(1000);
        }
        producer.close();
    }


}